import request from '@/utils/request'
import Qs from 'qs'

export default {
  /* 订单预览 */
  orderPreview: function({addressId, cartIds, couponId, memberId}){
    return request({
      method: 'POST',
      url: '/order/orderPreview',
      data: Qs.stringify({
        addressId: addressId,
        cartIds: cartIds,
        couponId: couponId,
        memberId: memberId
      })
    })
  },
  /* 订单创建 */
  createOrder: function({addressId, cartIds, couponId, memberId}){
    return request({
      method: 'POST',
      url: '/order/createOrder',
      data: Qs.stringify({
        addressId: addressId,
        cartIds: cartIds,
        couponId: couponId,
        memberId: memberId
      })
    })
  },
  /* 秒杀订单创建 */
  createSecKillOrder: function({addressId, secKillId, memberId}){
    return request({
      method: 'POST',
      url: '/order/createSecKillOrder',
      data: Qs.stringify({
        addressId: addressId,
        secKillId: secKillId,
        memberId: memberId
      })
    })
  },
  /* 获取订单列表 */
  orderList: function({memberId, orderStatus, pageNo, pageSize}){
    return request({
      method: 'GET',
      url: '/order/orderList',
      params: {
        memberId: memberId,
        orderStatus: orderStatus,
        pageNo: pageNo,
        pageSize: pageSize
      }
    })
  },
  /* 获取订单详情 */
  orderDetail: function(id){
    return request({
      method: 'GET',
      url: '/order/orderInfo/'+id
    })
  },
  /* 获取售后申请列表 */
  orderReturnApplyList: function({memberId, returnStatus, pageNo, pageSize}){
    return request({
      method: 'GET',
      url: '/order/orderReturnApplyList',
      params: {
        memberId: memberId,
        returnStatus: returnStatus,
        pageNo: pageNo,
        pageSize: pageSize
      }
    })
  },
  /* 获取售后详情 */
  orderReturnApplyDetail: function(id){
    return request({
      method: 'GET',
      url: '/order/orderReturnApplyInfo/'+id
    })
  },
  /* 申请售后 */
  orderReturnApply: function({orderId, goodsIds, goodsNums, returnType, applyReason, applyPic}){
    return request({
      method: 'POST',
      url: '/order/orderReturnApply',
      data: Qs.stringify({
        orderId: orderId,
        goodsIds: goodsIds,
        goodsNums: goodsNums,
        returnType: returnType,
        applyReason: applyReason,
        applyPic: applyPic
      })
    })
  },
  /* 确认收货 */
  orderReceive: function({orderId}){
    return request({
      method: 'POST',
      url: '/order/orderReceive',
      data: Qs.stringify({
        orderId: orderId
      })
    })
  },
  /* 余额支付 */
  orderPay4Balance: function(orderId){
    return request({
      method: 'POST',
      url: '/pay/balance/pay/'+orderId
    })
  }
}
